package com.example.studentknowledgesys.dao;

import com.example.studentknowledgesys.entity.Tag;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author 光的代言人
 */
@Mapper
public interface TagMapper {
    // 插入标签
    @Insert("INSERT INTO tags(name) VALUES(#{name})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertTag(Tag tag);
    // 更新标签
    @Update("UPDATE tags SET name = #{name}, updated_at = NOW() WHERE id = #{id}")
    int updateTag(Tag tag);

    // 删除标签
    @Delete("DELETE FROM tags WHERE id = #{id}")
    int deleteTagById(Long id);

    // 根据ID查询标签
    @Select("SELECT * FROM tags WHERE id = #{id}")
    Tag selectTagById(Long id);

    // 查询所有标签
    @Select("SELECT * FROM tags")
    List<Tag> selectAllTags();

    // 根据名称查询标签
    @Select("SELECT * FROM tags WHERE name = #{name}")
    Tag selectTagByName(String name);
}
